package com.tender.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tender.condition.SysMsgAssoUserCondition;
import com.tender.entity.SysMsgAssoUserEntity;
import com.tender.mapper.SysMsgAssoUserMapper;
import com.tender.service.SysMsgAssoUserService;
import com.tender.utils.SnowFlakeUtil;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SysMsgAssoUserServiceImpl extends ServiceImpl<SysMsgAssoUserMapper, SysMsgAssoUserEntity> implements SysMsgAssoUserService {

    @Override
    public Boolean bindMsgWithUser(SysMsgAssoUserCondition condition) {
        SysMsgAssoUserEntity saveEntity = new SysMsgAssoUserEntity();
        saveEntity.setId(Long.valueOf(SnowFlakeUtil.nextId()));
        saveEntity.setUserId(condition.getUserId());
        saveEntity.setMsgId(condition.getMsgId());
        // 预留字段
        if (null == condition.getTenantId()) {
            saveEntity.setTenantId(0L);
        }
        Date now = new Date();
        saveEntity.setGmtUpdate(now);
        saveEntity.setGmtCreate(now);
        // 更新、插入者都是 userId
        saveEntity.setCreateUserId(condition.getUserId());
        saveEntity.setUpdateUserId(condition.getUserId());

        return this.save(saveEntity);
    }

}
